<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>轮播图管理</title>
    {include file="/admin/head"/}
</head>
<body>
<div class="x-body">
    <div class="layui-form">
        <input type="text" id="id" name="id" value="{$info.id|default=0}" style="display: none;">
        <div class="layui-form-item">
            <label class="layui-form-label">
                Title
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$info.name|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                Rotating Images
            </label>
            <div class="layui-input-inline">
                <div class="layui-form-item">
                    <img src="/static/img/none.jpg" style="width: 100px;" id="images_id" onclick="addimages()">
                    <input type="file" id="images-array-file" name="images-file" style="display: none" onchange="imagesfile(this)" accept="image/*">
                    <div class="image-list" id="image-list">
                        {notempty name="info.images"}
                        {volist name="info.images" id="value"}
                        <div class="image-info" id="images_id{$value.id}">
                            <a href="javascript:del_image('{$value.id}');">X</a>
                            <input type="number" name="images_id" value="{$value.id}">
                            <img src="{$value.image}"  id="images_image{$value.id}" onclick="saveimages('{$value.id}')">
                        </div>
                        {/volist}
                        {/notempty}
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                Links地址
            </label>
            <div class="layui-input-inline">
                <input type="text" id="url" name="url" required lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$info.url|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                上级目录
            </label>
            <div class="layui-input-inline">
                <select id="pid">
                    <option value="0">顶级</option>
                    {volist name="all" id="value"}
                    <option value="{$value.id}" {notempty name="info.pid"} {eq name="info.pid" value="$value.id"} selected {/eq} {/notempty}>
                    {$value.name}
                    </option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                List template
            </label>
            <div class="layui-input-inline">
                <select id="list_template">
                    <option value="">无</option>
                    {volist name="template" id="value"}
                    <option value="{$value}" {notempty name="info.list_template"}{eq name="info.list_template" value="$value"}selected{/eq}{/notempty}>{$value}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                详细模板
            </label>
            <div class="layui-input-inline">
                <select id="info_template">
                    <option value="">无</option>
                    {volist name="template" id="value"}
                    <option value="{$value}" {notempty name="info.info_template"}{eq name="info.info_template" value="$value"}selected{/eq}{/notempty}>{$value}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                Content
            </label>
            <div class="layui-input-inline">
                <script type="text/javascript" charset="utf-8" src="/ueditor-plus/dist/ueditor.config.js"></script>
                <script type="text/javascript" charset="utf-8" src="/ueditor-plus/dist/ueditor.all.js"></script>
                <script type="text/javascript" charset="utf-8" src="/ueditor-plus/lang/zh-cn/zh-cn.js?7a537435"></script>
                <script id="editor" type="text/plain" style="width:800px;height:500px;">
                    {notempty name="info.content"}{$info.content|raw}{/notempty}
                </script>
                <script type="text/javascript">
                // 初始化编辑器
                var ue = UE.getEditor('editor');
                </script>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                Confirm
            </button>
        </div>
    </div>
</div>
<script>

    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(){
            let message = {
                name:document.getElementById('name').value,
                url:document.getElementById('url').value,
                list_template:document.getElementById('list_template').value,
                info_template:document.getElementById('info_template').value,
                images_id:getimagesid(),
                pid:document.getElementById('pid').value,
                content:ue.getContent()
            };
            console.log(message);
            //发异步，把数据提交给php
            post('/sys/image/save?id={$info.id|default=0}',message);
        });
    });
    function post_result(res){
        layer.alert("OptionSuccess", {icon: 6},function () {
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
            parent.location.reload();
        });
    }
</script>
</body>
</html>